

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>设置我的资料</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/admin.css"  media="all">
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">设置我的资料</div>
          <div class="layui-card-body" pad15>
            <form id="form" class="layui-form" action="" lay-filter="component-form-group">
              <!-- <div class="layui-form-item">
                <label class="layui-form-label">我的角色</label>
                <div class="layui-input-inline">
                  <select name="role" lay-verify="">
                    <option value="1" selected>超级管理员</option>
                    <option value="2" disabled>普通管理员</option>
                    <option value="3" disabled>审核员</option>
                    <option value="4" disabled>编辑人员</option>
                  </select> 
                </div>
                <div class="layui-form-mid layui-word-aux">当前角色不可更改为其它角色</div>
              </div> -->
              <!-- <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                  <input type="text" name="username" value="xianxin" readonly class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
              </div> -->
              <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                  <input type="text" data-tagname="input" name="realname" value="" lay-verify="" autocomplete="off" placeholder="请输入姓名" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline">
                <select name="sex" id="sex" data-tagname="select">
                  <option value=""></option>
                  <option value="0">未知</option>
                  <option value="1">男</option>
                  <option value="2" >女</option>
                </select>
                </div>
                <!-- <div class="layui-input-block">
                  <input type="radio" name="sex" value="男" title="男">
                  <input type="radio" name="sex" value="女" title="女" checked>
                </div> -->
              </div>
 
              <div class="layui-form-item">
                <label class="layui-form-label">手机</label>
                <div class="layui-input-inline">
                  <input data-tagname="input" type="text" name="mobilePhone" value="" lay-verify="" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-inline">
                  <input data-tagname="input" type="text" name="email" value="" lay-verify="" autocomplete="off" class="layui-input">
                </div>
              </div>

              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit="" lay-filter="setmyinfo">确认修改</button>
                  <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
                </div>
              </div>
            </form>
            
          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="../../layuiadmin/layui/layui.js" ></script>  
  <script>

  layui.config({
    base: '../../layuiadmin/' //静态资源所在路径
  }).extend({
    app: 'lib/app' 
  }).define(["app","form", "upload"], function(exports) {
    var $ = layui.$,
    layer = layui.layer,
    setter = layui.setter, 
    app = layui.app, 
    form = layui.form;

    start();

    function start(){
      getMyInfo();
      addEvent();
    }

    function addEvent(){
      form.verify({
        pass: [/^[\S]{6,12}$/, "密码必须6到12位，且不能出现空格"]
        
      }),form.on("submit(setmyinfo)", function(t) {
        app.ajax({
            url: app.getUrl('updateMyInfo'), 
            data:t.field,
            type: "post",
            dataType: "json",
            success: function(res){
              parent.layer.msg('修改成功');
            }
        });
        return false;
      });
    }

    function getMyInfo(){

      app.ajax({
        url: app.getUrl('getMyInfo'), 
        type: "post",
        dataType: "json",
        success: function(data){
          $.each(data, function(key, value) {

            var tag=$('#form [name="'+key+'"]');
            var tagname=tag.data('tagname');
            if(tagname){
              if(tagname=='select'){
                tag.val(value);
              }else{
                tag.val(value);
              }
            }

            //初始化数据后再渲染
            form.render(null, 'component-form-group');

          });
        }
      });
      
    }



  });
  </script>
</body>
</html>